/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.assistants;

import com.alee.laf.WebLookAndFeel;
import com.alee.utils.XmlUtils;
import com.alee.utils.collection.ValuesTable;
import com.rag.core.DropType;
import com.rag.core.Item;
import com.rag.core.ItemClass;
import com.rag.core.ItemType;
import com.rag.managers.BaseManager;
import com.rag.managers.RagManager;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * User: mgarin Date: 09.04.12 Time: 15:18
 */

public class CustomItemInsert
{
    public static void main ( String[] args )
    {
        WebLookAndFeel.install ();
        BaseManager.initialize ();
        RagManager.initialize ();

        ValuesTable<String, Item> items = RagManager.getKnownItems ();

        //////////////////////////////////////////////////////

        Map<String, Item> custom = new HashMap<String, Item> ();

        Item motrPartyHatItem = new Item ();
        motrPartyHatItem.setId ( "19998" );
        motrPartyHatItem.setItemType ( ItemType.armor );
        motrPartyHatItem.setItemClass ( ItemClass.upper );
        motrPartyHatItem.setDropType ( DropType.event );
        motrPartyHatItem.setTitle ( "MOTR Party Hat" );
        motrPartyHatItem.setSynonym ( "Шапка Мотропати" );
        motrPartyHatItem.setCardSuffix ( null );
        motrPartyHatItem.setDescription (
                "A gothic hat created to celebrate a first organized party supported by MOTRonline<br>" +
                        "All Stats + 1<br>" +
                        "[<span style='color:blue'>Phoenix Mask Combo</span>]<br>" +
                        "[<span style='color:blue'>Wings of Elven Guard Combo</span>]<br>" +
                        "[<span style='color:blue'>Romantic Rose Combo</span>]" );
        motrPartyHatItem.setScript (
                "{ bonus bStr,1; bonus bAgi,1; bonus bVit,1; bonus bInt,1; bonus bDex,1; bonus bLuk,1; },{},{}" );
        motrPartyHatItem.setSlotCount ( 0 );
        motrPartyHatItem.setBuyPrice ( null );
        motrPartyHatItem.setSellPrice ( null );
        motrPartyHatItem.setWeight ( 30f );
        motrPartyHatItem.setAttack ( null );
        motrPartyHatItem.setDefense ( 2 );
        motrPartyHatItem.setRequiredLvl ( 0 );
        motrPartyHatItem.setWeaponLvl ( null );
        motrPartyHatItem.setRange ( null );
        motrPartyHatItem.setDropRates ( null );
        custom.put ( motrPartyHatItem.getId (), motrPartyHatItem );

        Item phoenixMaskItem = new Item ();
        phoenixMaskItem.setId ( "19988" );
        phoenixMaskItem.setItemType ( ItemType.armor );
        phoenixMaskItem.setItemClass ( ItemClass.middle );
        phoenixMaskItem.setDropType ( DropType.event );
        phoenixMaskItem.setTitle ( "Phoenix Mask" );
        phoenixMaskItem.setSynonym ( "Маска Феникса" );
        phoenixMaskItem.setCardSuffix ( null );
        phoenixMaskItem.setDescription ( "A mysterious mask made of Phoenix feather<br>" +
                "It was created to celebrate a second organized party supported by MOTRonline<br>" +
                "MDEF + 3<br>" +
                "[<span style='color:blue'>+ MOTR Party Hat</span>]" +
                "+1 STR if the user has more than 77 base STR points<br>" +
                "+1 AGI if the user has more than 77 base AGI points<br>" +
                "+1 VIT if the user has more than 77 base VIT points<br>" +
                "+1 INT if the user has more than 77 base INT points<br>" +
                "+1 DEX if the user has more than 77 base DEX points<br>" +
                "+1 LUK if the user has more than 77 base LUK points<br>" +
                "[<span style='color:blue'>Wings of Elven Guard Combo</span>]<br>" +
                "[<span style='color:blue'>Romantic Rose Combo</span>]" );
        phoenixMaskItem.setScript (
                "{ bonus bMdef,3; if(getequipid(1)==19998) {if(readparam(bStr)>=77) bonus bStr,1; if(readparam(bAgi)>=77) bonus bAgi,1; if(readparam(bVit)>=77) bonus bVit,1; if(readparam(bInt)>=77) bonus bInt,1; if(readparam(bDex)>=77) bonus bDex,1; if(readparam(bLuk)>=77) bonus bLuk,1;} },{},{}" );
        phoenixMaskItem.setSlotCount ( 0 );
        phoenixMaskItem.setBuyPrice ( null );
        phoenixMaskItem.setSellPrice ( null );
        phoenixMaskItem.setWeight ( 10f );
        phoenixMaskItem.setAttack ( null );
        phoenixMaskItem.setDefense ( 0 );
        phoenixMaskItem.setRequiredLvl ( 0 );
        phoenixMaskItem.setWeaponLvl ( null );
        phoenixMaskItem.setRange ( null );
        phoenixMaskItem.setDropRates ( null );
        custom.put ( phoenixMaskItem.getId (), phoenixMaskItem );

        Item romanticRoseItem = new Item ();
        romanticRoseItem.setId ( "19990" );
        romanticRoseItem.setItemType ( ItemType.armor );
        romanticRoseItem.setItemClass ( ItemClass.lower );
        romanticRoseItem.setDropType ( DropType.event );
        romanticRoseItem.setTitle ( "Romantic Rose" );
        romanticRoseItem.setSynonym ( "Романтическая Роза" );
        romanticRoseItem.setCardSuffix ( null );
        romanticRoseItem.setDescription (
                "A beautiful rose that is placed in the mouth for romantic mood<br>" +
                        "It was created to celebrate a fourth organized party supported by MOTRonline<br>" +
                        "DEX +1<br>" +
                        "[<span style='color:blue'>+ MOTR Party Hat or Phoenix Mask</span>]<br>" +
                        "Increases damage inflicted on Undead monster by 5%<br>" +
                        "[<span style='color:blue'>+ MOTR Party Hat & Phoenix Mask</span>]<br>" +
                        "Reduces damage from Undead monster by 5%" );
        romanticRoseItem.setScript (
                "{ bonus bDex,1; if((getequipid(1)==19998)||(getequipid(9)==19988)) { bonus2 bAddRace,RC_Undead,5; } if((getequipid(1)==19998)&&(getequipid(9)==19988)){bonus2 bSubRace,RC_Undead,5; } },{},{}" );
        romanticRoseItem.setSlotCount ( 0 );
        romanticRoseItem.setBuyPrice ( null );
        romanticRoseItem.setSellPrice ( null );
        romanticRoseItem.setWeight ( 10f );
        romanticRoseItem.setAttack ( null );
        romanticRoseItem.setDefense ( 0 );
        romanticRoseItem.setRequiredLvl ( 0 );
        romanticRoseItem.setWeaponLvl ( null );
        romanticRoseItem.setRange ( null );
        romanticRoseItem.setDropRates ( null );
        custom.put ( romanticRoseItem.getId (), romanticRoseItem );

        Item wingsOfElvenGuardItem = new Item ();
        wingsOfElvenGuardItem.setId ( "19989" );
        wingsOfElvenGuardItem.setItemType ( ItemType.armor );
        wingsOfElvenGuardItem.setItemClass ( ItemClass.lower );
        wingsOfElvenGuardItem.setDropType ( DropType.event );
        wingsOfElvenGuardItem.setTitle ( "Wings of Elven Guard" );
        wingsOfElvenGuardItem.setSynonym ( "Крылья Эльфа-Стража" );
        wingsOfElvenGuardItem.setCardSuffix ( null );
        wingsOfElvenGuardItem.setDescription ( "A little wings of elven guard<br>" +
                "They were created to celebrate a third organized party supported by MOTRonline<br>" +
                "Receive 5% less damage from Boss enemies<br>" +
                "Receive 5% more damage from normal enemies<br>" +
                "[<span style='color:blue'>+ MOTR Party Hat or Phoenix Mask</span>]<br>" +
                "Receive 5% less damage from normal enemies<br>" +
                "[<span style='color:blue'>+ MOTR Party Hat and Phoenix Mask</span>]<br>" +
                "Maximum SP + 80" );
        wingsOfElvenGuardItem.setScript (
                "{ bonus2 bSubRace,10,5; bonus2 bSubRace,11,-5; if((getequipid(1)==19998)||(getequipid(9)==19988)){bonus2 bSubRace,11,5;} if((getequipid(1)==19998)&&(getequipid(9)==19988)){ bonus bMaxSP,80;} },{},{}" );
        wingsOfElvenGuardItem.setSlotCount ( 0 );
        wingsOfElvenGuardItem.setBuyPrice ( null );
        wingsOfElvenGuardItem.setSellPrice ( null );
        wingsOfElvenGuardItem.setWeight ( 10f );
        wingsOfElvenGuardItem.setAttack ( null );
        wingsOfElvenGuardItem.setDefense ( 0 );
        wingsOfElvenGuardItem.setRequiredLvl ( 0 );
        wingsOfElvenGuardItem.setWeaponLvl ( null );
        wingsOfElvenGuardItem.setRange ( null );
        wingsOfElvenGuardItem.setDropRates ( null );
        custom.put ( wingsOfElvenGuardItem.getId (), wingsOfElvenGuardItem );

        System.out.println ( "Adding " + custom.size () + " new item(s) into old data map..." );
        items.putAll ( custom );

        // todo корректные иконки для MOTR-итемов

        //////////////////////////////////////////////////////

        //        for ( Item item : items.values () )
        //        {
        //            System.out.println (item.getScript ());
        //            Source source = new Source ( item.getScript () );
        //            source.fullSequentialParse ();
        //            item.setScript ( source.getTextExtractor ().toString () );
        //            System.out.println (item.getScript ());
        //        }

        //////////////////////////////////////////////////////

        System.out.println ( "Saving " + items.size () + " items into data file..." );
        XmlUtils.toXML ( items.getValues (), new File ( "remote/data.xml" ) );

        System.out.println ( "Finished." );
    }
}